package de.hwrBerlin.dataMining.dataStructure;

import de.hwrBerlin.dataMining.controller.observer.Observer;
import de.hwrBerlin.dataMining.controller.observer.Subject;

public class Model extends Subject implements Observer {

	private TableData _table;
	private TreeNode _interactiveTree;
	private TreeNode _automaticTree;

	public void setTable(TableData pTable) {
		if (_table != null) {
			_table.removeObserver(this);
		}
		_table = pTable;
		_table.addObserver(this);
		updateAllTable(_table);
	}

	public TableData getTable() {
		return _table;
	}

	public void setInteractiveTree(TreeNode pInteractiveTree) {
		if (_interactiveTree != null) {
			_interactiveTree.removeObserver(this);
		}
		_interactiveTree = pInteractiveTree;
        if(_interactiveTree != null){
            _interactiveTree.addObserver(this);
        }
		updateAllInteractiveTree(_interactiveTree);
	}

	public void setAutomaticTree(TreeNode pInteractiveTree) {
		if (_automaticTree != null) {
			_automaticTree.removeObserver(this);
		}
		_automaticTree = pInteractiveTree;
		if(_automaticTree != null){
	        _automaticTree.addObserver(this);
		}
		updateAllAutomaticTree(_automaticTree);
	}
	
	public TreeNode getAutomaticTree(){
		return _automaticTree;
	}

	public TreeNode getInteractiveTree(){
		return _interactiveTree;
	}

	public void reset() {
	    setTable(null);
	    setInteractiveTree(null);
	    setAutomaticTree(null);
	}

	public void updateTable(TableData pTableData) {
		updateAllTable(pTableData);
	}

	public void updateTree(TreeNode pTree) {
		if (pTree == _automaticTree) {
			updateAllAutomaticTree(_automaticTree);
		} else if (pTree == _interactiveTree) {
			updateAllInteractiveTree(_interactiveTree);
		}
	}

	public void updateInteractiveTree(TreeNode pTree) {
	}

	public void updateAutomaticTree(TreeNode pTree) {
	}

}
